// 导航守卫

import router from '@/router'
import store from '@/store' 
// 白名单：不需要登陆就可访问的页面
const pageList = ['/login', '/404']
router.beforeEach((to, from, next) => {

  // console.log('to', to)
  if (store.state.login.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 要去的页面是  to.path
    // 白名单 pageList
    if (pageList.includes(to.path.toLowerCase())) {
        console.log('next',next);
      next()
    } else {
      next('/login')
    }  
  }
})

